<template>
  <div class="footer-page">
    <div class="details_page">
      <div class="top flex flex-between align-center">
        <div class="top_left">
          <img src="../../assets/images/tip-icon.png" alt="tip" />
          <span>{{detailInfo.refund_status_name}}</span>
        </div>
        <div class="top_right" v-if="detailInfo.refund_status == 2 || detailInfo.refund_status == 3">
          <el-button class="btns" size="small" type="warning" @click="agreeRefunds(detailInfo)"
            >同意退款</el-button>
          <el-button class="btns" size="small" type="danger" @click="refuseRefunds(detailInfo)"
            >拒绝退款</el-button>
        </div>
      </div>
      <div class="bottom_info">
        <div class="orderInfo">
          <div class="orderInfo_left">
            <div class="mar20">
              <img src="../../assets/images/xcx.png" alt="icon" />
              <span class="orderInfo_title">订单信息</span>
            </div>
            <div class="line">
              <p>
                订单编号：<span>{{ detailInfo.trade_no }}</span>
              </p>
              <p>
                创建时间：<span>{{ detailInfo.create_time }}</span>
              </p>
              <p>
                实付金额：<span>￥{{ detailInfo.paid_total_rent }}</span>
              </p>
            </div>
          </div>
          <div class="orderInfo_right">
            <div class="mar20">
              <img src="../../assets/images/xcx.png" alt="icon" />
              <span class="orderInfo_title">退款信息</span>
            </div>
            <div>
              <p>
                退款编号：<span>{{ detailInfo.trade_no }}</span>
              </p>
              <p>
                应退金额：<span>{{ detailInfo.refund_amount }}</span>
              </p>
              <p>
                应补足金额：<span>￥{{ detailInfo.deduct_amount }}</span
                ><el-button
                  class="checkBtn"
                  type="text"
                  @click="toDetails(detailInfo.id)"
                  >查看明细</el-button
                >
              </p>
            </div>
          </div>
        </div>
        <div class="orderGoods">
          <div class="mar20">
            <img src="../../assets/images/xcx.png" alt="icon" />
            <span class="orderInfo_title">退货订单商品</span>
          </div>
          <el-table :data="tableData">
            <el-table-column label="商品信息">
              <template slot-scope="scope">
                <img
                  class="goodsImg"
                  :src="$globalObj.imgBaseUrl + scope.row.imgurl"
                  alt=""
                />
                <p class="p1 text-ellipsis">{{ scope.row.goods_title }}</p>
                <p class="p2 text-ellipsis">{{ scope.row.setmeal_title }}</p>
              </template>
            </el-table-column>
            <el-table-column
              align="center"
              label="数量"
              prop="amount"
              width="100"
            />
            <el-table-column
              align="center"
              label="租期"
              prop="create_time"
              width="180"
            />
            <el-table-column align="center" label="总租金" width="200">
              <template slot-scope="scope">
                <span>￥{{ scope.row.rent_total }}</span>
              </template>
            </el-table-column>
            <el-table-column align="center" label="实付金额" width="200">
              <template slot-scope="scope">
                <span v-if="scope.row.paid_total_rent"
                  >￥{{ scope.row.paid_total_rent }}</span
                >
              </template>
            </el-table-column>
            <el-table-column align="center" label="应退金额" width="200">
              <template slot-scope="scope">
                <span>￥{{ scope.row.refund_amount }}</span>
              </template>
            </el-table-column>
          </el-table>
          <div class="refundInfo">
            <p>
              退款类型：<span class="red-font">{{
                detailInfo.refund_type == 1 ? "仅退款" : "退货退款"
              }}</span>
            </p>
            <p>
              退款原因：<span class="red-font">{{
                detailInfo.refund_reason
              }}</span>
            </p>
            <p>
              退款描述：<span class="red-font">{{
                detailInfo.refund_desc
              }}</span>
            </p>
            <div >
              <el-image
                v-for="(item, index) in imgList" 
                :key="index"
                class="refundImg"
                :src="$globalObj.imgBaseUrl + item"
                :preview-src-list="[$globalObj.imgBaseUrl + item]"
              >
              </el-image>
            </div>
          </div>
        </div>
        <div class="orderRecords">
          <div class="mar20">
            <img src="../../assets/images/xcx.png" alt="icon" />
            <span class="orderInfo_title">订单操作记录</span>
          </div>
          <el-table :data="recordData">
            <!-- <el-table-column align="center" label="退款状态">
              <template slot-scope="scope">
                <span>{{
                  scope.row.refund_status == 2
                    ? "用户申请退款"
                    : scope.row.refund_status == 3
                    ? "平台待审核"
                    : scope.row.refund_status == 4
                    ? "审核拒绝"
                    : scope.row.refund_status == 6
                    ? "退款完成"
                    : "其他"
                }}</span>
              </template>
            </el-table-column> -->
            <el-table-column align="center" label="内容" prop="content" />
            <el-table-column align="center" label="操作人" prop="operate_user" />
            <el-table-column align="center" label="时间" prop="create_time" />
          </el-table>
        </div>
      </div>
    </div>
    <div slot="footer" class="dialog-footer setBtn">
      <el-button type="primary" @click="toClose()">关闭</el-button>
    </div>
    <check-details ref="checkDetails" :refund-id="currentId"> </check-details>
    <agree-refund ref="agreeRefund" :refund-id="currentId" :order-id="orderId" :refund-status="refundStatus" type="datail"> </agree-refund>
    <refuse-refund ref="refuseRefund" :refund-id="currentId" :refund-status="refundStatus"> </refuse-refund>

  </div>
</template>

<script>
import { orderRefundInfo } from "@/api/orderRefund";
import checkDetails from "./dialog/checkDetails.vue";
import agreeRefund from "./dialog/agreeRefund.vue";
import refuseRefund from "./dialog/refuseRefund.vue";

export default {
  props: ["id"],
  components: { checkDetails, agreeRefund, refuseRefund },
  data() {
    return {
      detailInfo: {},
      tableData: [],
      recordData: [],
      imgList: [],
      currentId: "",
      orderId: "",
      refundStatus: "",
    };
  },
  methods: {
    getList() {
      orderRefundInfo(this.id).then(res => {
        this.detailInfo = res;
        this.recordData = res.order_log
        this.tableData = [{}];
        for (var i in res) {
          this.$set(this.tableData[0], i, res[i]);
        }
        this.imgList = res.refund_image ? res.refund_image.split(',') : [];
      });
    },
    toClose() {
      this.$router.go(-1);
    },
    toDetails(id) {
      this.currentId = id;
      this.$refs.checkDetails.dialogVisible = true;
    },
    agreeRefunds(row){
      this.currentId = row.id;
      this.orderId = row.order_id;
      this.refundStatus = row.refund_status;
      this.$refs.agreeRefund.dialogVisible = true;
    },
    refuseRefunds(row){
      this.currentId = row.id
      this.refundStatus = row.refund_status
      this.$refs.refuseRefund.dialogVisible = true;
    }
  },
  mounted() {
    this.getList()
  },
};
</script>

<style lang="scss" scoped>
.footer-page {
  padding-bottom: 0;
}
img {
  vertical-align: middle;
  margin-right: 17px;
}
.mar20 {
  margin-bottom: 20px;
}
.details_page {
  border: 1px solid #e6e6e6;
  .top {
    height: 80px;
    background: #f5f5f5;
    padding: 0 12px 0 25px;
    .top_left {
      img {
        width: 36px;
        height: 36px;
      }
      span {
        font-size: 22px;
        font-weight: bold;
        color: #ff4247;
        vertical-align: middle;
      }
    }
    .top_right {
      .btns {
        height: 40px;
        border-radius: 3px;
      }
    }
  }
  .bottom_info {
    padding: 30px 30px 80px;
    .orderGoods {
      margin-bottom: 30px;
      .goodsImg {
        width: 50px;
        height: 50px;
        float: left;
      }
      .p1 {
        color: #2891fb;
      }
      .p2 {
        color: #999999;
      }
      .refundInfo {
        border: 1px solid #e6e6e6;
        border-top: none;
        padding: 20px;
        p {
          line-height: 35px;
        }
        div {
          padding-left: 35px;
          margin-top: 5px;
        }
        .refundImg {
          // width: 90px;
          height: 90px;
        }
      }
    }
    .orderInfo {
      height: 180px;
      .orderInfo_title {
        font-size: 16px;
        color: #666666;
        vertical-align: middle;
      }
      p {
        line-height: 35px;
      }
      .orderInfo_left,
      .orderInfo_right {
        width: 50%;
        float: left;
      }
      .line {
        border-right: 1px solid #ccc;
        margin-right: 50px;
      }
      .checkBtn {
        margin-left: 15px;
      }
    }
  }
}
.setBtn {
  text-align: center;
  margin-top: 30px;
  //   border-top: 1px solid #eee;
  height: 70px;
  line-height: 70px;
}
</style>